#pragma once
#ifndef ENEMY_H
#define ENEMY_H

#include <Entity.h>
#include <EntityManager.h>
#include <AnimationPlayer.h>
// Entity interations
#include <Collision.h>
#include <Contact.h>
// Physics
#include <Particle.h>
#include <ForceGenerator.h>
#include <ForceRegistry.h>
// 
#include "Node.h"
#include <list>


class Enemy : public Entity
{
private:
	AnimationPlayer* anims;
	Particle particle;
	Node* m_baseNode;
	Node* m_currentNode;
	Node* m_prevNode;
	// Experience gain by hacking nodes.
	int m_experience;
	// Holds Countdown timer
	float m_timer;
	int m_currentLevel;
	// List contains the current chain of hacked nodes.
	std::list<Node*> m_securedNodes;
	// Flags to determine if left analogue stick was at a given position.
	bool wasStickRight;
	bool wasStickLeft;
	bool wasStickDown;
	bool wasStickUp;
public:
	Enemy(AnimationPlayer* enemyAnims, Node* baseNode)
		: Entity("Enemy"),
		anims(enemyAnims),
		particle(D3DXVECTOR3(50,50,0), D3DXVECTOR3(0,0,0), 10.0f)
	{
		m_baseNode = baseNode;
		m_currentNode = m_baseNode;
		m_prevNode = m_baseNode;
		m_securedNodes.push_front(m_baseNode);
		// Initialise variables.
		m_experience = 0;
		m_timer = 0.0f;
		m_currentLevel = 0;
		// Set the current animation
		anims->playAnimation("Idle");
		// Set entity texture with the single framed idle animation.
		setTexture(anims->getCurrentAnimation()->getTexture());
		setPosition(m_baseNode->getPosition());
		// Initialise ananlgue flags.
		wasStickRight = false;
		wasStickLeft = false;
		wasStickDown = false;
		wasStickUp = false;
	}
	~Enemy() { delete anims; }
	// Position get & set.
	D3DXVECTOR3 getPosition() { return particle.position; }
	virtual void setPosition(D3DXVECTOR3 newPosition)
	{ position = newPosition; particle.position = newPosition; }
	// Texture get.
	IDirect3DTexture9* getTexture() { return texture; }
	// Base node get & set.
	Node* getBaseNode() { return m_baseNode; }
	void setBaseNode(Node* baseNode) { m_baseNode = baseNode; }
	// Current node get & set.
	Node* getCurrentNode() { return m_currentNode; }
	void setCurrentNode(Node* currentNode) { m_currentNode = currentNode; }
	// Previous node get & set.
	Node* getPrevNode() { return m_prevNode; }
	void setPrevNode(Node* currentNode) { m_prevNode = currentNode; }
	// Experience get & set.
	int getExperience() { return m_experience; }
	void setExperience(int experience) { m_experience = experience; }
	// Timer get & set.
	float getTimer() { return m_timer; }
	void setTimer(float timer) { m_timer = timer; }
	// Current level get & set.
	int getCurrentLevel() { return m_currentLevel; }
	void setCurrentLevel(int currentLevel) { m_currentLevel = currentLevel; }

	// Override virtual entity functions.
	void update(float frameTime);
	void draw(ID3DXSprite* sprite);
	void handleMessage(Message message);
};

#endif // ENEMY_H